﻿using System;
using System.Runtime.Serialization;

namespace JXT.PrimaryKey.Batman.Core.WcfService
{
    /// <summary>
    /// 操作结果对象
    /// </summary>
    [DataContract(Namespace = ServiceEnvironment.ModelNamespace)]
    public class OperationResult
    {
        /// <summary>
        /// 操作是否成功
        /// </summary>
        [DataMember]
        public bool IsSuccess { get; protected set; }

        /// <summary>
        /// 操作相关消息
        /// </summary>
        [DataMember]
        public string Message { get; protected set; }

        /// <summary>
        /// 创建操作结果对象
        /// </summary>
        /// <param name="isSuccess">操作是否成功</param>
        /// <returns>操作对象</returns>
        public static OperationResult Create(bool isSuccess)
        {
            return new OperationResult()
            {
                IsSuccess = isSuccess,
                Message = String.Empty
            };
        }

        /// <summary>
        /// 创建操作结果对象
        /// </summary>
        /// <param name="isSuccess">操作是否成功</param>
        /// <param name="message">操作结果消息</param>
        /// <returns>操作对象</returns>
        public static OperationResult Create(bool isSuccess, string message)
        {
            return new OperationResult()
            {
                IsSuccess = isSuccess,
                Message = message
            };
        }

        /// <summary>
        /// 默认的成功消息
        /// </summary>
        public readonly static OperationResult Success = Create(true, String.Empty);

        /// <summary>
        /// 默认的失败消息
        /// </summary>
        public readonly static OperationResult Fault = Create(false, String.Empty);
    }
}
